/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

/**
 * <p>Project: javaseapp - Img2
 * <p>Powered by webrx On 2021-08-12 17:43:48
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img2 {
    public static void main(String[] args) {
        int w = 800, h = 800, t = 2;
        //建立缓冲图像
        var img = new BufferedImage(w, h, t);
        var rand = new Random();
        //画笔
        var g = img.createGraphics();
        //设置图像中文本，线程的平滑
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, --w, --h);

        g.setColor(Color.WHITE);
        g.fillOval(w / 2 - 200, h / 2 - 200, w / 2, h / 2);
        g.setColor(Color.BLACK);
        g.fillArc(199, 199, 400, 400, 90, 180);
        g.fillOval(300, 399, 200, 200);

        g.setColor(Color.WHITE);
        g.fillOval(300, 199, 200, 200);
        g.fillOval(350, 450, 100, 100);

        g.setColor(Color.BLACK);
        g.fillOval(350, 250, 100, 100);

        //在图像画布上写字
        //Font font = new Font("微软雅黑", Font.BOLD, 80);
        //g.setFont(font);
        //g.setColor(Color.WHITE);
        //g.drawString("hello world", w / 2 - 140 - 1, h - 100 - 1);
        //g.setColor(Color.BLACK);
        //g.drawString("hello world", w / 2 - 140 + 2, h - 100 + 2);
        //Color cc = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
        //g.setColor(Color.ORANGE);
        //g.drawString("hello world", w / 2 - 140, h - 100);

        try {
            ImageIO.write(img, "png", new File("b.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            var run = Runtime.getRuntime();
            run.exec("cmd /k start b.png");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
